package com.sztx.pay.center.rpc.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.sztx.pay.center.common.annotation.SlaveQueryAnnotation;
import com.sztx.pay.center.common.yhbf.YHBFSensitiveEnc;
import com.sztx.pay.center.core.service.BankUtilService;
import com.sztx.pay.center.rpc.api.domain.BankInfo;
import com.sztx.pay.center.rpc.api.service.BankRpcService;
import com.sztx.se.core.service.impl.BaseServiceImpl;

@Service
public class BankRpcServiceImpl extends BaseServiceImpl implements BankRpcService {

	@Autowired
	private BankUtilService bankUtilService;
	
	
	@Override
	@SlaveQueryAnnotation
	public BankInfo queryBankCardBin(String bankCardNo) {
		com.sztx.pay.center.core.service.bean.BankInfo bInfo = bankUtilService.queryBankInfo(bankCardNo);
		
		return changeBankInfo(bInfo);
		
	}

	@Override
	@SlaveQueryAnnotation
	public List<BankInfo> findBankList(int type) {
		List<BankInfo> resultList = null;
		
		List<com.sztx.pay.center.core.service.bean.BankInfo> list = bankUtilService.querySupportedBankList(type);
		if (list != null && !list.isEmpty()) {			
			resultList = new ArrayList<BankInfo>();
			
			for (com.sztx.pay.center.core.service.bean.BankInfo bInfo : list) {				
				resultList.add(changeBankInfo(bInfo));
			}			
		}
		
		LOG.info("findBankList result:"+JSONObject.toJSONString(resultList));
		return resultList;
	}
	
	
	
	private BankInfo changeBankInfo(com.sztx.pay.center.core.service.bean.BankInfo bInfo){	
		
		if (bInfo == null) {
			return null;
		}
		
		BankInfo bankInfo = new BankInfo();
		
		bankInfo.setBankId(bInfo.getBankId());
		bankInfo.setBankName(bInfo.getBankName());
		bankInfo.setBankType(bInfo.getBankType());
		bankInfo.setBigLogoUrl(bInfo.getBigLogoUrl());
		bankInfo.setCardType(bInfo.getCardType());
		bankInfo.setSmallLogoUrl(bInfo.getSmallLogoUrl());
		bankInfo.setSwiftCode(bInfo.getSwiftCode());
		bankInfo.setPassClipherPay(bInfo.isPassClipherPay());
//		try {
//			BeanUtils.copyProperties(bankInfo, bInfo);
//		} catch (Exception e) {
//			LOG.error("结果转换失败", e);
//		}
		
		return bankInfo;
		
	}
	
	

}
